import Vue from 'vue'
import Router from 'vue-router'
//import HelloWorld from '@/components/HelloWorld'
import Home from "../components/Home";

import login from "../components/login";
import Manage from "../components/Manage";
import login11 from "../components/login11";
import indexlogin from "../components/indexlogin";

Vue.use(Router)
//导航守卫 路由拦截 (在我们的路由的切换的时候 我们在进行拦截我们的跳转)

//这个是我们的根目录
const router = new Router({
  routes: [
    {
      path: '/home',
      name: 'home',
      component: Home,
      children: [{
        path: '/index1',
        component: () => import('../views/index/index.vue')
      },
        {
          path: '/storage',
          component: () => import('../views/user/index')

        },
        {
          path: '/info',
          component: () => import('../views/info/index'),
          children: [{
            path: '/info/list',
            component: () => import('../views/info/information')
          },

            {
              path: '/info/user',
              component: () => import('../views/info/userlist')
            }
          ]
        }
      ]
    },
    {
      path: '/index',
      name: 'home1',
      component: indexlogin
    },
    {
      path: '/login123',
      component: () => import('../views/login/index')
    },

    {
      path: '/login',
      component: ()=>import('../views/login/index2')
    },
    {
      path: '/manage',
      component: Manage,

    },
    {
      path: '/login11',
      component: login11

    },
    {
      path: '/test',
      component: ()=>import('../views/user/test')

    },
    {
      path: '/login12',
      component: ()=>import('../views/login/index2')

    },

  ],
})
//路由只要是切换的话 我们就会调用这里面的方法
//


//路由守卫



router.beforeEach((to, from, next) => {
  //这个·是打印我们的去哪里 到哪里
  // console.log(to);
  // console.log(from);
  //next();//这样是可以进行放行的(这个是决定能不能给你放行的)
  //验证token只有存在的时候 才能跳转到

  let token = localStorage.getItem("token");
  if (token || to.path === "/login") {
    next();
  } else {
    next("/login");//这个就是让你随便进去就行
  }
})
export default router;

